﻿using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.WebControls;
namespace LJ.ColorPickerField
{
    public class ColorPickerField: SPFieldText
    {
        private const string JSLinkUrl = "~site/_layouts/15/LJ.ColorPickerField/CSRFieldType.js";
        public ColorPickerField(SPFieldCollection fields, string name)
            : base(fields, name) { }
        public ColorPickerField(SPFieldCollection fields, string typename, string name)
            : base(fields, typename, name) { }
        public override string JSLink
        {
            get
            {
                try
                {
                    var control = ((ColorPickerFieldControl)this.FieldRenderingControl).ControlMode;
                    return "";
                }
                catch (Exception)
                {
                    return JSLinkUrl;
                    //throw;
                }
                
            }
            set
            {
                base.JSLink = value;
            }
        }

     
        public override BaseFieldControl FieldRenderingControl
        {
            get
            {
                BaseFieldControl fieldcontrol = new ColorPickerFieldControl();
                fieldcontrol.FieldName = this.InternalName;
                return fieldcontrol;
            }
        }
    }

}
